import axios from '@/common/axiosHttp.js'
export default {
	state: {
		navArr:[],
		opusList:[],
    imgClassifyArr:[],
    imgArr:[],
 	},
	mutations: {
		setNavArr (state,arr) {
		  state.navArr=arr;
		},
		setOpusList (state,arr){
			state.opusList=arr;
		},
    setImgClassifyArr (state,arr){
      arr.forEach((item)=>{
        item.value=item.id;
      });
      state.imgClassifyArr=arr; 
    },
    setImgArr(state,arr){
      state.imgArr=arr;
    },
    changeImgArr(state,arr){
      state.imgArr=[...arr,...state.imgArr];
    }
	},
	actions:{
    getNavArr ({ commit }) {
    	axios.get('/nav')
      .then((response)=>{
      	commit('setNavArr',response.data);
      });
    },
    getOpusList ({commit}){
    	axios.get('/opus/opuslist')
      .then((response)=>{
      	commit('setOpusList',response.data);
      });
    },
    getImgClassifyArr ({commit}){
      axios.get('/photos/imgclassify')
      .then((response)=>{
        commit('setImgClassifyArr',response.data);
      });
    },
    getImgArr({commit}){
      axios.get('/photos/img/')
      .then((response)=>{
        commit('setImgArr',response.data);
      });
    },
    changeImgArr({commit,state}){
      let id=state.imgArr[0].id||1;
      axios.get('/photos/img/?id='+id)
      .then((response)=>{
        commit('changeImgArr',response.data);
      });
    }
  }
}